package org.vectrics.recruiter.struts.tag;

import org.vectrics.SystemException;
import org.vectrics.common.html.Table;
import org.vectrics.common.util.StringUtils;
import org.vectrics.company.Company;
import org.vectrics.hibernate.ThreadProperties;
import org.vectrics.recruiter.RecruitServiceLocator;
import org.vectrics.recruiter.job.Job;
import org.vectrics.recruiter.user.ResumeScanBatch;
import org.vectrics.recruiter.user.ResumeScanBatchJob;
import org.vectrics.user.Person;

/**
 * @author mmoore
 */
public class UserBufferForResumeScanTag extends UserBufferTag {

	private static final long serialVersionUID = -2121197198995321619L;
	
	private String resumeScanBatchId = null;
        
    protected ResumeScanBatch getResumeScanBatch() {
        ResumeScanBatch resumeScanBatch = null;
    	if (StringUtils.isNullOrBlank(this.resumeScanBatchId) == false) {
	        Long id = new Long(this.resumeScanBatchId);
	        resumeScanBatch = RecruitServiceLocator.getRecruitUserService().findResumeScanBatch(id);
	        if (resumeScanBatch == null)
	        	throw new SystemException("Could not find scan batch for id = " + this.resumeScanBatchId);
    	}
        return(resumeScanBatch);
    }
    
    protected void createJobBufferContent(Table contentTable, Job jobForBuffer) {
    	ThreadProperties.getSession().clear();
    	ResumeScanBatchJob resumeScanBatchJob = RecruitServiceLocator.getRecruitUserService().findResumeScanBatchJob(jobForBuffer);
    	if ((resumeScanBatchJob == null) 
    			|| (resumeScanBatchJob.getResumeScanBatch().getId().equals(this.getResumeScanBatch().getId()) == false)) {

    		String href = this.getContextPath() + "/admin/jobs/candidatescan/add.do?jobId=" + jobForBuffer.getId() 
	        	+ "&scanId=" + this.getResumeScanBatch().getId(); 
            this.makeLinkRow(contentTable, this.getPhrase("phrase.attach.scan.to.job"), href); 
    	} else {
    		log.debug("Show link to allow scan result candidates to be made into this job's candidates");
			String href = this.getContextPath() + "/admin/jobs/resumeScanResults.do?batchId=" + 
				this.getResumeScanBatch().getId().toString()
				+ "&jobId=" + jobForBuffer.getId().toString();
    		this.makeLinkRow(contentTable, "Select candidates for job", href);
    	}
    }
    
    
    protected void createCompanyBufferContent(Table contentTable, Company companyForBuffer) {
    }
    
    
    protected void createPersonBufferContent(Table contentTable, Person personForBuffer) {
    }

	public String getResumeScanBatchId() {
		return resumeScanBatchId;
	}

	public void setResumeScanBatchId(String resumeScanBatchId) {
		this.resumeScanBatchId = resumeScanBatchId;
	}
    
}
